﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMS.MainClasses;
using GMS.Dinasty.DAL;
using System.Data.SqlClient;


namespace GMS.Dinasty.Applications
{
    public partial class ApplicationsForm : ChildForms
    {
        public ApplicationsForm()
        {
            InitializeComponent();
            ApplicationsGridView.DataSource = _applicationsList;
            ApplicationsContentGridView.DataSource = _applicationsContent;
            ApplicationsGridView.AutoGenerateColumns = false;
            ApplicationsContentGridView.AutoGenerateColumns = false;
        }

        BindingSource _applicationsList = new BindingSource();
        BindingSource _applicationsContent = new BindingSource();
        SqlConnection _connection = new SqlConnection();

        DAApplication _daaplication;
        DataSet _ds = new DataSet();

        private string _connectionString;
        public string ConnectionsTring
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }
        private void ApplicationsForm_Load(object sender, EventArgs e)
        {
            _connectionString = "server=pavel;uid=pavel;pwd=123456;database=GMSDatabase";
            _connection.ConnectionString = _connectionString;

            _daaplication = new DAApplication(_connection);
            _ds.Tables.Add(_daaplication.ApplicationsList());
            _ds.Tables.Add(_daaplication.ApplicationsContent());

            DataColumn _parent = _ds.Tables["ApplicationsList"].Columns["Id"];
            DataColumn _child = _ds.Tables["ApplicationsContent"].Columns["IdApplication"];
            DataRelation _relation = new DataRelation("applicationListContent", _parent, _child);

            _ds.Relations.Add(_relation);

            _applicationsList.DataSource = _ds;
            _applicationsList.DataMember = "ApplicationsList";

            _applicationsContent.DataSource = _applicationsList;
            _applicationsContent.DataMember = "applicationListContent";

        }
    }
}
